<?php

/**
 * This is the model class for table "Reservation".
 *
 * The followings are the available columns in table 'Reservation':
 * @property integer $id
 * @property string $reserve_reservationdate_from
 * @property string $reserve_reservationdate_to
 * @property integer $reserve_noofadults
 * @property integer $reserve_noofchildren
 * @property integer $unit_id
 * @property integer $account_id
 * @property double $total_cost
 *
 * The followings are the available model relations:
 * @property Unit $unit
 * @property Account $account
 */
class Reservation extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Reservation the static model class
	 */
	 
	 public function getUnitPrice()
	{
    return $this->id.'/'.$this->unit_price;
	}
	 
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'Reservation';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('unit_id, account_id, reserve_reservationdate_from, reserve_reservationdate_to, reserve_noofadults, reserve_noofchildren', 'required'),
			array('reserve_noofadults, reserve_noofchildren, unit_id, account_id, total_cost', 'numerical'),
			array('reserve_reservationdate_from, reserve_reservationdate_to', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, reserve_reservationdate_from, reserve_reservationdate_to, reserve_noofadults, reserve_noofchildren, unit_id, account_id', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'unit' => array(self::BELONGS_TO, 'Unit', 'unit_id'),
			'account' => array(self::BELONGS_TO, 'Account', 'account_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'reserve_reservationdate_from' => 'Start Date of Reservation',
			'reserve_reservationdate_to' => 'End Date of Reservation',
			'reserve_noofadults' => 'No. of Adults',
			'reserve_noofchildren' => 'No. of Children',
			'unit_id' => 'Unit No.',
			'account_id' => 'Account Name',
			'total_cost' => 'Total Cost',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('reserve_reservationdate_from',$this->reserve_reservationdate_from,true);
		$criteria->compare('reserve_reservationdate_to',$this->reserve_reservationdate_to,true);
		$criteria->compare('reserve_noofadults',$this->reserve_noofadults);
		$criteria->compare('reserve_noofchildren',$this->reserve_noofchildren);
		$criteria->compare('unit_id',$this->unit_id);
		$criteria->compare('account_id',$this->account_id);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}